<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Provide a return value for an existing function</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.uopz-set-property.html">« uopz_set_property</a></li>
      <li style="float: right;"><a href="function.uopz-set-static.html">uopz_set_static »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.uopz.html">Uopz 函数</a></li>
    <li>Provide a return value for an existing function</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.uopz-set-return" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">uopz_set_return</h1>
  <p class="verinfo">(PECL uopz 5, PECL uopz 6, PECL uopz 7)</p><p class="refpurpose"><span class="refname">uopz_set_return</span> &mdash; <span class="dc-title">Provide a return value for an existing function</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.uopz-set-return-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>uopz_set_return</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$function</code></span>, <span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$execute</code><span class="initializer"> = <strong><code>false</code></strong></span></span>): <span class="type">bool</span></div>

  <div class="methodsynopsis dc-description"><span class="methodname"><strong>uopz_set_return</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$class</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$function</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">bool</span> <code class="parameter">$execute</code><span class="initializer"> = <strong><code>false</code></strong></span></span><br>): <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   Sets the return value of the <code class="parameter">function</code> to <code class="parameter">value</code>. If <code class="parameter">value</code>
   is a Closure and <code class="parameter">execute</code> is set, the Closure will be executed in place of the original function.
   It is possible to call the original function from the Closure.
  </p>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    This function replaces <span class="methodname"><a href="function.uopz-rename.html" class="methodname">uopz_rename()</a></span>.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.uopz-set-return-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt>
<code class="parameter">class</code></dt>

    <dd>

     <p class="para">
 The name of the class containing the function
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">function</code></dt>

    <dd>

     <p class="para">
 The name of an existing function
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">value</code></dt>

    <dd>

     <p class="para">
 The value the function should return. If a Closure is provided and the execute flag is set, the Closure will be executed in place of the original function.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">execute</code></dt>

    <dd>

     <p class="para">
 If true, and a Closure was provided as the value, the Closure will be executed in place of the original function.
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.uopz-set-return-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
  True if succeeded, false otherwise.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.uopz-set-return-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-640">
   <p><strong>示例 #1 <span class="function"><strong>uopz_set_return()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />uopz_set_return</span><span style="color: #007700">(</span><span style="color: #DD0000">"strlen"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">42</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">strlen</span><span style="color: #007700">(</span><span style="color: #DD0000">"Banana"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程会输出：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
42
</pre></div>
   </div>
  </div>
  <div class="example" id="example-641">
   <p><strong>示例 #2 <span class="function"><strong>uopz_set_return()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />uopz_set_return</span><span style="color: #007700">(</span><span style="color: #DD0000">"strlen"</span><span style="color: #007700">,&nbsp;function(</span><span style="color: #0000BB">$str</span><span style="color: #007700">)&nbsp;{&nbsp;return&nbsp;</span><span style="color: #0000BB">strlen</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">)&nbsp;*&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">;&nbsp;},&nbsp;</span><span style="color: #0000BB">true&nbsp;</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">strlen</span><span style="color: #007700">(</span><span style="color: #DD0000">"Banana"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程会输出：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
12
</pre></div>
   </div>
  </div>
  <div class="example" id="example-642">
   <p><strong>示例 #3 <span class="function"><strong>uopz_set_return()</strong></span> class example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">My&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;function&nbsp;</span><span style="color: #0000BB">strlen</span><span style="color: #007700">(</span><span style="color: #0000BB">$arg</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">strlen</span><span style="color: #007700">(</span><span style="color: #0000BB">$arg</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /></span><span style="color: #0000BB">uopz_set_return</span><span style="color: #007700">(</span><span style="color: #0000BB">My</span><span style="color: #007700">::class,&nbsp;</span><span style="color: #DD0000">"strlen"</span><span style="color: #007700">,&nbsp;function(</span><span style="color: #0000BB">$str</span><span style="color: #007700">)&nbsp;{&nbsp;return&nbsp;</span><span style="color: #0000BB">strlen</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">)&nbsp;*&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">;&nbsp;},&nbsp;</span><span style="color: #0000BB">true&nbsp;</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">My</span><span style="color: #007700">::</span><span style="color: #0000BB">strlen</span><span style="color: #007700">(</span><span style="color: #DD0000">"Banana"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程会输出：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
12
</pre></div>
   </div>
  </div>
 </div>



</div></div></div></body></html>